package de.yvert.jingle.impl.openexr;

import java.io.IOException;

public class ChannelListAttribute extends Attribute
{

public static final String TYPE = "chlist";

private final ChannelList channels;

public ChannelListAttribute(String name, ChannelList channels)
{
	super(name);
	this.channels = channels;
}

public ChannelListAttribute(String name, Channel[] channels)
{ this(name, new ChannelList(channels)); }

public ChannelList getChannels()
{ return channels; }

@Override
public String toString()
{ return "chlist \""+getName()+"\" = "+channels; }

int calculateSize()
{
	int size = 1;
	for (int i = 0; i < channels.size(); i++)
		size += channels.get(i).calculateSize();
	return size;
}

@Override
public void write(ExrOutputStream out) throws IOException
{
	out.writeString(getName());
	out.writeString(TYPE);
	out.writeInt(calculateSize());
	for (int i = 0; i < channels.size(); i++)
	{
		Channel c = channels.get(i);
		out.writeString(c.name);
		out.writeInt(c.pixelType.getCode());
		out.writeInt(c.reserved);
		out.writeInt(c.xSampling);
		out.writeInt(c.ySampling);
	}
	out.writeString(null);
}



}
